package de.tum.team26.eistpoll.server;

import java.util.List;
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;

/**
 * Class to store the Persistant Manager
 */
public final class PMF {
	
	// From the GWT Totorial
    private static final PersistenceManagerFactory pmfInstance =
        JDOHelper.getPersistenceManagerFactory("transactions-optional");

    private PMF() {}

    public static PersistenceManagerFactory get() {
        return pmfInstance;
    }
    

    /**
     * Get all Polls in a List ...
     * @return List of Polls
     */
	@SuppressWarnings("unchecked")
	public static List<PollDS> getPolls(){
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query;
		List<PollDS> temp = null;
    	try{ 
    		query = pm.newQuery(PollDS.class);
    		temp = (List<PollDS>) query.execute();
    		temp.size();
    		if (temp!= null){
    			for (PollDS e : temp){
    				e.getPersistantData();
    			}
    		}
    	} catch (javax.jdo.JDOObjectNotFoundException e) {
			 
		 } finally{
    		pm.close();
    	}
    	return temp;

    }
}